package creator.ui.graphics;

import creator.ui.controller.InternalFrom;
import creator.ui.controller.Processor;
import creator.ui.graphics.polaroid.Animation;
import java.awt.Canvas;
import java.awt.Graphics;
import java.awt.Image;
import java.util.ArrayList;
import java.util.Iterator;

public abstract class Magicanvas extends Canvas {

  private static final long serialVersionUID = 9175036060534282211L;
  public ArrayList<Animation> ANIMATIONS;

  public Magicanvas() {
    this.ANIMATIONS = new ArrayList();
    initialAnimations();
    loadMagicanvas();
  }

  public abstract void initialAnimations();

  private void loadMagicanvas() {
    if (this.ANIMATIONS != null) {
      Animation animation;
      for (
        Iterator localIterator = this.ANIMATIONS.iterator();
        localIterator.hasNext();
        animation.loadBeanParameter(this)
      ) animation = (Animation) localIterator.next();
    }
  }

  public void detectionJump() {
    Animation animation;
    for (
      Iterator localIterator = this.ANIMATIONS.iterator();
      localIterator.hasNext();
      animation.loadBeanParameter(this)
    ) animation = (Animation) localIterator.next();
  }

  public ArrayList<Animation> getAnimations() {
    return this.ANIMATIONS;
  }

  public void paint(Graphics g) {
    if (this.ANIMATIONS != null) {
      Animation animation;
      for (
        Iterator localIterator = this.ANIMATIONS.iterator();
        localIterator.hasNext();
        animation.paint(g)
      ) animation = (Animation) localIterator.next();
    }
  }

  public void update(Graphics g) {
    Image offScreenImage = createImage(
      Processor.getFrame().getWidth(),
      Processor.getFrame().getHeight()
    );
    paint(offScreenImage.getGraphics());
    g.drawImage(offScreenImage, 0, 0, null);
  }
}
